package net.lab1024.smartadmin.module.business.atmosphere.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.lab1024.smartadmin.common.domain.PageResultDTO;
import net.lab1024.smartadmin.common.domain.ResponseDTO;
import net.lab1024.smartadmin.module.business.atmosphere.dao.AtmosphereDao;
import net.lab1024.smartadmin.module.business.atmosphere.domain.dto.AtmosphereAddDTO;
import net.lab1024.smartadmin.module.business.atmosphere.domain.dto.AtmosphereQueryDTO;
import net.lab1024.smartadmin.module.business.atmosphere.domain.dto.AtmosphereUpdateDTO;
import net.lab1024.smartadmin.module.business.atmosphere.domain.entity.AtmosphereEntity;
import net.lab1024.smartadmin.module.business.atmosphere.domain.vo.AtmosphereExcelVO;
import net.lab1024.smartadmin.module.business.atmosphere.domain.vo.AtmosphereVO;
import net.lab1024.smartadmin.util.SmartBeanUtil;
import net.lab1024.smartadmin.util.SmartPageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * [ ���򻷾� ]
 *
 * @author wuhq
 * @version 1.0
 * @company ��������
 * @copyright (c)  ��������Inc. All rights reserved.
 * @date 2021-11-19 11:22:46
 * @since JDK1.8
 */
@Service
public class AtmosphereService {

    @Autowired
    private AtmosphereDao atmosphereDao;

    /**
     * ����id��ѯ
     */
    public AtmosphereEntity getById(Long id){
        return  atmosphereDao.selectById(id);
    }

    /**
     * ��ҳ��ѯ
     * @author wuhq
     * @date 2021-11-19 11:22:46
     */
    public ResponseDTO<PageResultDTO<AtmosphereVO>> queryByPage(AtmosphereQueryDTO queryDTO) {
        Page page = SmartPageUtil.convert2QueryPage(queryDTO);
        IPage<AtmosphereVO> voList = atmosphereDao.queryByPage(page, queryDTO);
        PageResultDTO<AtmosphereVO> pageResultDTO = SmartPageUtil.convert2PageResult(voList);
        return ResponseDTO.succData(pageResultDTO);
    }

    /**
     * ���
     * @author wuhq
     * @date 2021-11-19 11:22:46
     */
    public ResponseDTO<String> add(AtmosphereAddDTO addDTO) {
        AtmosphereEntity entity = SmartBeanUtil.copy(addDTO, AtmosphereEntity.class);
        atmosphereDao.insert(entity);
        return ResponseDTO.succ();
    }

    /**
     * �༭
     * @author wuhq
     * @date 2021-11-19 11:22:46
     */
    @Transactional(rollbackFor = Exception.class)
    public ResponseDTO<String> update(AtmosphereUpdateDTO updateDTO) {
        AtmosphereEntity entity = SmartBeanUtil.copy(updateDTO, AtmosphereEntity.class);
        atmosphereDao.updateById(entity);
        return ResponseDTO.succ();
    }

    /**
     * ɾ��
     * @author wuhq
     * @date 2021-11-19 11:22:46
     */
    @Transactional(rollbackFor = Exception.class)
    public ResponseDTO<String> deleteByIds(List<Long> idList) {
        atmosphereDao.deleteByIdList(idList);
        return ResponseDTO.succ();
    }

    /**
     * ��ѯȫ����������
     * @author wuhq
     * @date 2021-11-19 11:22:46
     */
    public List<AtmosphereExcelVO> queryAllExportData(AtmosphereQueryDTO queryDTO) {
        return atmosphereDao.queryAllExportData( queryDTO);
    }

    /**
     * ������ѯ��������
     * @author wuhq
     * @date 2021-11-19 11:22:46
     */
    public List<AtmosphereExcelVO> queryBatchExportData(List<Long> idList) {
        return atmosphereDao.queryBatchExportData(idList);
    }
}
